#include "stdafx.h"
#include "NetDataHander.h"
#include "CommandDefine.h"
#include "ParamBase.h"
#include "ParamCreate.h"
SharedPointer<CNetDataHander> CNetDataHander::m_pDatahander;

CNetDataHander::CNetDataHander()
{
	m_isHanderData = false;
}


CNetDataHander::~CNetDataHander()
{
}

void CNetDataHander::HanderOneData(PVData data)
{
	QPair<const unsigned char*, int> pairTemp = CCommandDefine::GetData(*data);
	CStreamLoadData dataLoad(pairTemp.first, pairTemp.second);
	while (!dataLoad.IsEof())
	{
		QString strFunName;
		int iParamNum;
		dataLoad.Read(strFunName);
		dataLoad.Read(iParamNum);
		ZMVector<SharedPointer<CNameCreateBase>> vParam;
		for (int i=0; i<iParamNum; ++i)
		{
			QString strParamType;
			dataLoad.Read(strParamType);
			SharedPointer<CNameCreateBase> pParam = SharedPointer<CNameCreateBase>(CObjectCreateFromName::GetInstance()->CreatObjFromName(strParamType, QString("Param_")));
			((CParamBase*)pParam.get())->Read(dataLoad);
			if (pParam.get())
			{
				vParam.push_back(pParam);
			}
		}

		RunFunction func = CObjectCreateFromName::GetInstance()->CreatFuncFromName(strFunName);
		func(vParam);
	}
}
